from brian import *
from brian.library.random_processes import *
from brian.library.synapses import  *


def napvtrap(x,y):
    a=x/y
    #if abs(a)<0.0001:
     #   return  1/(2+a)
    #else:
     #   return 1/(exp(a)+1)
    return 1/(exp(a)+1)
    
def napefun(x,y):
    a = x/y 
    #if abs(a)<0.0001:
     #   return 1+a
    #else:
     #   return exp(a)
    return exp(a)
            
 
def m_inf_na(V):
    return napvtrap(-(V+35),7.8)   
    
def h_inf_na(V):
    return napvtrap((V+55),7)

def tau_h_na(V):
    return msecond*(30/(napefun((V+50),15)+napefun(-(V+50),16)))

def m_inf_k(V):
    return napvtrap(-(V+28),15)

def tau_m_k(V):
    return msecond*(7/(napefun(V+40,40)+napefun(-(V+40),50)))

def m_inf_can(V):
    return napvtrap(-(V+30),5)

def h_inf_can(V):
    return napvtrap(V+45,5)

def m_inf_cal(V):
    return napvtrap(-(V+40),7)

def m_inf_nap(V):
    return napvtrap(-V-47.1,3.1)

def h_inf_nap(V):
    return napvtrap(V+59,8)

def tau_h_nap(V):
    return msecond*(2*1200/(napefun(V+59,16)+napefun(-V-59,16)))

def current_inj(t):
    if t > 0*msecond:
        return -0.5*namp
    else:
        return 0*mamp